package pk.nak.client.activity;

import pk.nak.adapters.PriceComparatorAdapter;
import pk.nak.client.R;
import pk.nak.data.EatOutMenuItem;
import pk.nak.data.EatOutMenuItemPrices;
import pk.nak.enums.AppVars;
import pk.nak.enums.ExtraIDs;
import pk.nak.requests.ComparePriceRequest;
import pk.nak.responses.ComparePriceResponse;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;

public class PriceComparisonActivity extends Activity {
	private EatOutMenuItem eomi;
	private ComparePriceResponse response = new ComparePriceResponse(){

		@Override
		public void onSuccess(String response) {
			// TODO Auto-generated method stub
			super.onSuccess(response);
			AppVars.pdWait.dismiss();
			PopulatePriceInfo(this.eomip);
		}
		
	};
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    this.setContentView(R.layout.pricecomparison);
	    
	    this.eomi = (EatOutMenuItem)this.getIntent().getSerializableExtra(ExtraIDs.SELECTED_MENUITEM_SERIALIZABLE);
	    
	    ComparePriceRequest request = new ComparePriceRequest(this.eomi.getID());
	    request.doRequst(response);
	    AppVars.pdWait = ProgressDialog.show(this, "Loading prices", "Loading...");
	    //this.PopulatePriceInfo();
	    // TODO Auto-generated method stub
	}

	public void PopulatePriceInfo(EatOutMenuItemPrices eomip){
		
		TextView tvName = (TextView) this.findViewById(R.id.tvMenuItemName);
		if ( tvName != null ) tvName.setText(this.eomi.getTitle());
		
		//EatOutMenuItemPrices eomip = AppVars.PriceComparator.getEatOutMenuItemPrices(this.eomi.getTitle());
		
		if ( eomip != null ){
			ListView lvItems = (ListView) this.findViewById(R.id.lvEatOutPrices);
			if ( lvItems != null ){
				PriceComparatorAdapter pca = new PriceComparatorAdapter(this,R.layout.eatoutpricecomparerow, eomip.getPriceGroups());
				lvItems.setAdapter(pca);
			}
		}
	}
}
